﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System
{
    public static class ExceptionExtensions
    {
        public static string GetFullException(this Exception exception)
        {
            var stackTrace = new StringBuilder();
            var ex = exception;

            while (ex != null) {
                stackTrace.AppendFormat("Message: {0}", ex.Message);
                stackTrace.AppendLine();
                stackTrace.AppendLine();

                stackTrace.Append("Stack Trace:");
                stackTrace.AppendLine();
                stackTrace.Append(ex.StackTrace);
                stackTrace.AppendLine();
                stackTrace.AppendLine();

                ex = ex.InnerException;
            }

            return stackTrace.ToString();
        }
    }
}
